package xdu.lz.netty.g_handler.tcp_handler;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ReplayingDecoder;

import java.util.List;

/**
 * @author lizhen
 * @date 2019/8/24 23:15
 * @desc
 */
public class MyPersonDecoder extends ReplayingDecoder<Void> {
    private int count = 0;
    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
        count ++;
        System.out.println();
        System.out.println("MyPersonDecoder decode invoke!");
        int length = in.readInt(); //直接读取，内部处理了
        byte[] content = new byte[length];

        in.readBytes(content);//直接读取，内部处理了

        PersonProtocol personProtocol = new PersonProtocol();
        personProtocol.setLength(length);
        personProtocol.setContent(content);

        out.add(personProtocol);
    }
}
